function [b1 b2 b3]=barycenter(x,y,x0,y0)
if nargin<=2
x0=[0 1 0];
y0=[0 0 1];
end
n=length(x);
m=length(y);
n0=length(x0);
m0=length(y0);
if n0~=3|m0~=3
    error('triangle parameter error!');
end
x1=x0(1);
x2=x0(2);
x3=x0(3);
y1=y0(1);
y2=y0(2);
y3=y0(3);
T=det([1 x1 y1;1 x2 y2; 1 x3 y3]);

if n~=m
    error('coordinate dimension does not agree!');
end

for i=1:n
   b1(i)=det([1 x(i) y(i);1 x2 y2; 1 x3 y3])/T;    
   b2(i)=det([1 x1 y1;1 x(i) y(i); 1 x3 y3])/T;
   b3(i)=det([1 x1 y1;1 x2 y2; 1 x(i) y(i)])/T;
end
b1=b1';
b2=b2';
b3=b3';

